//
//  PlayVideoUserinfo.m
//  iphoneLive
//
//  Created by 志刚杨 on 2017/10/25.
//  Copyright © 2017年 cat. All rights reserved.
//

#import "PlayVideoUserinfo.h"
#import <UIButton+WebCache.h>
#import "videoListModel.h"
@implementation PlayVideoUserinfo
{
    UIView *_bgview;
}
-(instancetype)init
{
    self = [super init];
    if(self)
    {
        [self initView];
    }
    return self;
}

-(void)initView
{
    
    _bgview = [[UIView alloc] init];
    _bgview.backgroundColor = CLightGray;
    _bgview.layer.cornerRadius = 15;
    _bgview.layer.masksToBounds = YES;
    _bgview.alpha = 0.7;
    [self addSubview:_bgview];

    //头像
    self.header = [[UIButton alloc] init];
    [self.header setBackgroundColor:[UIColor grayColor]];
    self.header.layer.cornerRadius = 20;
    self.header.layer.masksToBounds = YES;
    
    [self.header addTarget:self action:@selector(headerClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_header];
    
    //username
    self.username = [[UILabel alloc] init];
    self.username.font = [UIFont systemFontOfSize:11];
    self.username.textColor = [UIColor whiteColor];
    [self addSubview:self.username];
    
    //title
    self.videoTitle = [[UILabel alloc] init];
    self.videoTitle.font = [UIFont systemFontOfSize:12];
    self.videoTitle.textColor = RGB(220, 220, 220);
    [self addSubview:self.videoTitle];
    
    //ids
    self.ids = [[UILabel alloc] init];
    self.ids = [[UILabel alloc] init];
    self.ids.font = [UIFont systemFontOfSize:11];
    self.ids.textColor = [UIColor whiteColor];
    self.ids.text = @"ID:998877";
    [self addSubview:self.ids];
    
    //关注按钮
    self.attrButton = [[QMUIFillButton alloc] initWithFillColor:MainColor titleTextColor:[UIColor whiteColor]];
    self.attrButton.hidden = YES;
    [self.attrButton setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
    [self addSubview:self.attrButton];
    self.attrButton.titleLabel.font = [UIFont systemFontOfSize:13];
    
    self.playNumber = [[UILabel alloc] init];
    self.playNumber = [[UILabel alloc] init];
    self.playNumber.font = [UIFont systemFontOfSize:11];
    self.playNumber.textColor = [UIColor whiteColor];
    [self addSubview:self.playNumber];

    //设置约束
    [self setLayout];

}

-(void)setLayout
{
    //头像
    [self.header mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(3);
        make.top.equalTo(self).offset(3);
        make.width.and.height.equalTo(@40);
    }];
    
    //头像
    [self.ids mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.header.mas_right).offset(3);
        make.top.equalTo(_bgview).offset(2);
    }];
    
    //昵称
    [self.username mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.header.mas_right).offset(3);
        make.top.equalTo(_bgview).offset(2);
    }];
    
    [self.playNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.header.mas_right).offset(3);
        make.top.equalTo(self.ids.mas_bottom).offset(2);
    }];
    
    //title
    [self.videoTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.header);
        make.top.equalTo(self.header.mas_bottom).offset(3);
//        make.centerY.equalTo(self.header);
    }];
//
    [self.attrButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self);
        make.centerY.equalTo(_bgview);
        make.width.equalTo(@33);
        make.height.equalTo(@33);
    }];
    
    [_bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(2);
        make.top.equalTo(self.header).offset(5);
        make.bottom.equalTo(self.header).offset(-5);
        make.right.equalTo(self);
    }];
}

-(void)setModel:(videoListModel *)model
{
    _model = model;
    self.ids.text = model.user_nickname;
    [self.header sd_setImageWithURL:[cyurl safeUrl:model.avatar] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"no_pic"]];
    self.playNumber.text = StringFromInteger(model.host_count);
//    [self.header sd_setImageWithURL:[Utils fixUrl:model.avatar ReturnURL:YES] forState:UIControlStateNormal];
//    self.username.text = model.user_nickname;
//    self.videoTitle.text = model.title;
    
}

//头像点击
-(void)headerClick
{
    if([self.delegate respondsToSelector:@selector(clickHeader)])
    {
        [self.delegate clickHeader];
    }
    else
    {
        NSLog(ASLocalizedString(@"检查是否设置了代理"));
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
